package cn.itcast.nems.common.web.controller.b;

import cn.itcast.nems.common.account.AccountHolder;
import cn.itcast.nems.common.account.AccountInfo;
import cn.itcast.nems.employee.dto.EmployeeDTO;
import cn.itcast.nems.employee.service.EmployeeService;
import cn.itcast.nems.manager.msas.MsasManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/b/account")
public class AccountController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsasManager msasManager;
    @Autowired
    private EmployeeService employeeService ;

    @GetMapping("/permissions")
    public ResponseEntity<Set<String>> permissions() {
        final AccountInfo account = AccountHolder.getRequiredAccountInfo();
        EmployeeDTO employeeDTO = new EmployeeDTO(account.getName(), account.getEmail(), account.getNumber()) ;
        // employeeService.checkAndSaveEmployee(employeeDTO);
        final Set<String> permissions = this.msasManager.getPermissions(account.getEmail());
        return ResponseEntity.ok(permissions);
    }
    /**
     * 获取当前登陆的用户信息
     * @return ResponseEntity
     */
    @GetMapping("/info")
    public ResponseEntity<?> userInfo() {
        final AccountInfo info = AccountHolder.getRequiredAccountInfo();
        return ResponseEntity.ok().body(info);
    }
}
